package com.code.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.code.dao.AdminMapper;
import com.code.dao.RoleMapper;
import com.code.pojo.Admin;
import com.code.pojo.Role;
import com.code.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;

import java.util.List;
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    AdminMapper adminMapper;

    @Autowired
    RoleMapper roleMapper;

    @Override
    public Admin findUserByUserName(String username) {
        Admin admin = new Admin();
        admin.setUsername(username);
        List<Admin> adminList = adminMapper.select(admin);
        if (CollectionUtils.isEmpty(adminList)) {
            return null;
        }else {
            return adminList.get(0);
        }

    }

    @Override
    public Role findRoleByAdmin(Integer rid) {
        return roleMapper.selectByPrimaryKey(rid);
    }
}
